<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    
<%  
String path = request.getContextPath();  
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $(".click").click(function(){
  $(".tip").fadeIn(200);
  });
  
  $(".tiptop a").click(function(){
  $(".tip").fadeOut(200);
});

  $(".sure").click(function(){
  $(".tip").fadeOut(100);
});

  $(".cancel").click(function(){
  $(".tip").fadeOut(100);
});

});


//校验用户是否已存在
function checkUser(){
	var username_Val = $("#username").val();
	$.ajax({
		url:"<%=basePath%>checkUser",
		data : {
			"username" : username_Val
		},
		dataType : "json",
		//编码设置
		contentType : "application/json;charset=utf-8",
		success : function(data) {
			if (data.msg != null) {
				alert(data.msg);
				$("#username").val("");
				$("#username").focus();
			} 
		},
		error:function(){
			alert("后台服务器出错，请联系系统管理员！");
		}
	})

}

function toValid(){
	//效验密码长度
	var pass= $("#password").val();
	if(pass.length() < 6 | pass.length() > 12){
		alert("密码长度6-12位");
		$("#password").val("");
		$("#password").focus();
	}
	//校验邮箱号码是否合法
	var mail = $("#email").val();
	var myReg = /^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/;
	//var regemail=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	if (!myReg.test(mail)) {
		alert("非合法的邮箱号，请确认！");
		$("#email").focus();
    } 
}
</script>

</head>


<body>
	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="userInfo.html">用户管理</a></li>
    <li><a href="userInfoAdd.html">添加</a></li>
    </ul>
    </div>
    
    <form action="<%=basePath %>addUser" method="post">
    <div class="formbody">
    <div class="formtitle"><span>用户基本信息</span></div>
    
    <ul class="forminfo">
    <li><label>姓名</label><input id="username" name="username" type="text" class="dfinput" value="" onchange="checkUser()"/></li>
    <li><label>密码</label><input id="password" name="password" type="password" class="dfinput" value="" onchange="toValid()"/></li>
    <li><label>性别</label><cite><input name="sex" type="radio" value="M" checked="checked" />男&nbsp;&nbsp;&nbsp;&nbsp;<input name="sex" type="radio" value="F" />女</cite></li>
    <li><label>邮箱</label><input id="email" name="email" type="text" class="dfinput" value="" onchange="toValid()" /></li>
	<li><label>密码提示问题</label><input name="question" type="text" class="dfinput" value="" onchange="toValid()" /></li>
	<li><label>密码提示答案</label><input name="answer" type="text" class="dfinput" value="" onchange="toValid()" /></li>
    <li><label>出生日期</label><input name="birthDay" type="text" class="dfinput" value="" onchange="toValid()" /></li>
    <li><label>角色</label><cite><select name="roleId" class="dfselect"><option value="0">请选择</option><option value="1" >管理员</option><option value="2">客户经理</option></select></cite></li>
    <li><label>&nbsp;</label><input name="" type="submit" class="btn" value="添加"/>&nbsp;&nbsp;&nbsp;&nbsp;<input name="" type="reset" class="btn" value="重置"/></li>
    </ul>
    
    </div>
    </form>
</body>

</html>
